﻿using System;
using System.Collections.Generic;
using DTO;
using System.Data;
using System.Data.SqlClient;


namespace DAO
{
    public class DAONguoiDung
    {
        public static DataTable DanhSachTaiKhoan()
        {
            return SQLDataProvider.ExecuteQueryString("Select USERID,USERNAME,VAITRO,TRANGTHAI From NguoiDung");
        }

        public static DataTable TimKiemTaiKhoan(DTONguoiDung nguoidung)
        {
            try
            {
                DataTable kq = null;
                List<SqlParameter> sqlParams = new List<SqlParameter>();
                sqlParams.Add(new SqlParameter("@username", nguoidung.UserName));
                sqlParams.Add(new SqlParameter("@vaitro", nguoidung.VaiTro));
                sqlParams.Add(new SqlParameter("@trangthai", nguoidung.TrangThai));
                kq = SQLDataProvider.ExecuteQuery("sp_TraCuuTaiKhoan", sqlParams);
                return kq;
            }
            catch (Exception ex)
            {
                throw ex;
            }            
        }

        public static int ThemTaiKhoan(DTONguoiDung nguoidung)
        {
            try
            {
                List<SqlParameter> sqlParams = new List<SqlParameter>();
                sqlParams.Add(new SqlParameter("@Username", nguoidung.UserName));
                sqlParams.Add(new SqlParameter("@Vaitro", nguoidung.VaiTro));
                sqlParams.Add(new SqlParameter("@Trangthai", nguoidung.TrangThai));
                return SQLDataProvider.ExecuteNoneQuery("sp_ThemTaiKhoan", sqlParams);
            }
            catch (Exception ex)
            {
                throw ex;
            }            
        }

        public static int CapNhatTaiKhoan(DTONguoiDung nguoidung)
        {
            try
            {
                List<SqlParameter> sqlParams = new List<SqlParameter>();
                sqlParams.Add(new SqlParameter("@Userid", nguoidung.UserId));
                sqlParams.Add(new SqlParameter("@Username", nguoidung.UserName));
                sqlParams.Add(new SqlParameter("@Vaitro", nguoidung.VaiTro));
                sqlParams.Add(new SqlParameter("@Trangthai", nguoidung.TrangThai));
                return SQLDataProvider.ExecuteNoneQuery("sp_CapNhatTaiKhoan", sqlParams);
            }
            catch (Exception ex)
            {
                throw ex;
            }     
        }

        public static int XoaTaiKhoan(DTONguoiDung nguoidung)
        {
            try
            {
                List<SqlParameter> sqlParams = new List<SqlParameter>();
                sqlParams.Add(new SqlParameter("@Userid", nguoidung.UserId));
                return SQLDataProvider.ExecuteNoneQuery("sp_XoaTaiKhoan", sqlParams);
            }
            catch (Exception ex)
            {
                throw ex;
            }   
        }

        public static DataTable ThongTinNguoiDung(string tentaikhoan)
        {
            try
            {
                List<SqlParameter> sqlParams = new List<SqlParameter>();
                sqlParams.Add(new SqlParameter("@Username", tentaikhoan));
                return SQLDataProvider.ExecuteQuery("sp_ThongTinNguoiDung", sqlParams);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public static int CapNhatMatKhau(DTONguoiDung nguoidung)
        {
            try
            {
                List<SqlParameter> sqlParams = new List<SqlParameter>();
                sqlParams.Add(new SqlParameter("@UserId", nguoidung.UserId));
                sqlParams.Add(new SqlParameter("@Password", nguoidung.Password));
                return SQLDataProvider.ExecuteNoneQuery("sp_CapNhatMatKhau", sqlParams);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
